home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / PowerLisp 2.01 / PowerLisp 2.01 ƒ / examples / primes.lisp < prev   
Lisp/Scheme  |  1995-03-09  |  484b  |  22 lines

  1. ;
  2. ;        File:        primes.lisp
  3. ;        Contents:    Lisp program to generate all the prime numbers
  4. ;                    between 1 and n. It is quick and dirty, and uses
  5. ;                    a brute force approach to calculating them (i.e. it
  6. ;                    tries all possibilites).
  7. ;
  8. (defun primes (n1 n2)
  9.     "Generate all the prime numbers between n1 and n2"
  10.     (do ((i n1 (1+ i)))
  11.         ((> i n2))
  12.         (block inner
  13.             (do ((j 2 (1+ j)))
  14.                 ((>= j i) (print i))
  15.                 (if (zerop (mod i j))    ; if found a divisor
  16.                      (return-from inner)))))) 
  17.  
  18.  
  19.  
  20.  
  21.  
  22.